#include "taskQueue.h"
#include <myHeader.h>

/* Usage:  */
int initQueue(taskQueue_t *pQueue){                                  
    memset(pQueue,0,sizeof(taskQueue_t));
    return 0;
}

int isQueueEmpty(taskQueue_t *pQueue){
    return (pQueue==NULL||pQueue->queueSize==0);
}

int enQueue(taskQueue_t *pQueue,usrInfo_t usrInfo){
    node_t *pNewNode=(node_t *)calloc(1,sizeof(node_t));
    ERROR_CHECK(pNewNode,NULL,"NewNode callloc");
    pNewNode->usrInfo=usrInfo;
    if(isQueueEmpty(pQueue)){
        pQueue->pFront=pNewNode;
    }
    else{
        pQueue->pRear->pNext=pNewNode;
    }
    pQueue->pRear=pNewNode;
    ++pQueue->queueSize;
    return 0;
}

int deQueue(taskQueue_t *pQueue){
    if(isQueueEmpty(pQueue)){
        return 0;
    }
    node_t *pTmp=pQueue->pFront;
    if(pQueue->queueSize==1){
        pQueue->pRear=NULL;
    }
    pQueue->pFront=pQueue->pFront->pNext;
    free(pTmp);
    --pQueue->queueSize;
    return 0;
}
